package com.ruoyi.cust.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cust.domain.CityNotice;
import com.ruoyi.cust.service.ICityNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 滚动通知Controller
 *
 * @author cjq
 * @date 2024-12-06
 */
@Api("资讯")
@RestController
@RequestMapping("/city/notice")
public class CityNoticeController extends BaseController {
    @Autowired
    private ICityNoticeService cityNoticeService;

    /**
     * 查询滚动通知列表
     */
    @ApiOperation("查询滚动通知列表")
    @PreAuthorize("@ss.hasPermi('city:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityNotice cityNotice) {
        startPage();
        List<CityNotice> list = cityNoticeService.selectCityNoticeList(cityNotice); return getDataTable(list);
    }

    /**
     * 导出滚动通知列表
     */
    @ApiOperation("导出滚动通知列表")
    @PreAuthorize("@ss.hasPermi('city:notice:export')")
    @Log(title = "滚动通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityNotice cityNotice) {
        List<CityNotice> list = cityNoticeService.selectCityNoticeList(cityNotice); ExcelUtil<CityNotice> util = new ExcelUtil<CityNotice>(CityNotice. class);
        util.exportExcel(response, list, "滚动通知数据");
    }

    /**
     * 获取滚动通知详细信息
     */
    @ApiOperation("获取滚动通知详细信息")
    @PreAuthorize("@ss.hasPermi('city:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Long noticeId) {
        return success(cityNoticeService.selectCityNoticeByNoticeId(noticeId));
    }

    /**
     * 新增滚动通知
     */
    @ApiOperation("新增滚动通知")
    @PreAuthorize("@ss.hasPermi('city:notice:add')")
    @Log(title = "滚动通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityNotice cityNotice) {
        return toAjax(cityNoticeService.insertCityNotice(cityNotice));
    }

    /**
     * 修改滚动通知
     */
    @ApiOperation("修改滚动通知")
    @PreAuthorize("@ss.hasPermi('city:notice:edit')")
    @Log(title = "滚动通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityNotice cityNotice) {
        return toAjax(cityNoticeService.updateCityNotice(cityNotice));
    }

    /**
     * 删除滚动通知
     */
    @ApiOperation("删除滚动通知")
    @PreAuthorize("@ss.hasPermi('city:notice:remove')")
    @Log(title = "滚动通知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds) {
        return toAjax(cityNoticeService.deleteCityNoticeByNoticeIds(noticeIds));
    }
}
